package org.cheetah.spring.xml;

import org.cheetah.activities.CallService;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

public class CallServiceDefinitionParser extends
		AbstractSingleBeanDefinitionParser {

	@Override
	protected Class<?> getBeanClass(Element element) {
		return CallService.class;
	}

	@Override
	protected void doParse(Element element, BeanDefinitionBuilder bean) {
		String serviceVar = element.getAttribute("service-var");
		String serviceRef = element.getAttribute("service-ref");

		if (StringUtils.hasText(serviceVar)) {
			bean.addPropertyValue("serviceVar", serviceVar);
		}
		if (StringUtils.hasText(serviceRef)) {
			bean.addPropertyReference("serviceRef", serviceRef);
		}
	}
}
